package com.arvato.common.filter;

import javax.servlet.Filter;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.DelegatingFilterProxy;
/**
 * springboot过滤器配置 必须要这样配置bean注入 
 * loginFilter才能被注入IOC容器 才能调用其他的业务bean
 * @author ZHAN655
 *
 */
@Configuration
public class FilterConfig  {
	
	@Bean
    public Filter loginFilter() {
        return new LoginFilter();
    }
	
    @Bean
    public FilterRegistrationBean someFilterRegistration1() {
        //新建过滤器注册类
        FilterRegistrationBean registration = new FilterRegistrationBean();
        // 添加我们写好的过滤器
        registration.setFilter( new DelegatingFilterProxy("loginFilter"));
        // 设置过滤器的URL模式
        registration.addUrlPatterns("/*");
        registration.setName("loginFilter");
        registration.setOrder(1);
        return registration;
    }

}
